<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Minappstemplatelist extends Model
{
    protected $table = 'minapps_template_list';
    protected $primaryKey = 'id';

    public static function getMinappsTemplateList()
    {
        return self::where("disable",1)->orderBy("id","DESC")->get();
    }

    public static function getMinappsTemplateListId()
    {
        return self::select("source_miniprogram_appid","template_id")->where("disable",1)->orderBy("id","DESC")->get();
    }

    public static function getLastTemplateList()
    {
        return self::select("id","source_miniprogram_appid","template_id")->where("disable",1)->orderBy("id","DESC")->first();
    }

    public static function getMinappsTemplate($source_miniprogram_appid)
    {
        return self::where("source_miniprogram_appid",$source_miniprogram_appid)->first();
    }

    public static function getMinappsTemplateByTemplateId($template_id)
    {
        return self::where("template_id",$template_id)->first();
    }

    public static function getMinappsTemplateBySourceMiniprogramAppid($source_miniprogram_appid)
    {
        return self::where("source_miniprogram_appid",$source_miniprogram_appid)->where("disable",1)->orderBy("id","DESC")->get();
    }

    public static function minappsTemplateUpdate($source_miniprogram_appid,$template_type,$source_miniprogram,$template_id,$user_desc,$user_version,$audit_status,$modify_domain,$webview_domain,$template_sort,$disable)
    {
        return self::where("source_miniprogram_appid",$source_miniprogram_appid)->update(["template_type"=>$template_type,"source_miniprogram"=>$source_miniprogram,"template_id"=>$template_id,"user_desc"=>$user_desc,"user_version"=>$user_version,"audit_status"=>$audit_status,"modify_domain"=>$modify_domain,"webview_domain"=>$webview_domain,"template_sort"=>$template_sort,"disable"=>$disable]);
    }

    public function minappsTemplateInsert($source_miniprogram_appid,$template_type,$source_miniprogram,$template_id,$user_desc,$user_version,$audit_status)
    {
        return self::insert(["template_type"=>$template_type,"source_miniprogram"=>$source_miniprogram,"template_id"=>$template_id,"user_desc"=>$user_desc,"user_version"=>$user_version,"audit_status"=>$audit_status,"source_miniprogram_appid"=>$source_miniprogram_appid]);
    }
}